home *** CD-ROM | disk | FTP | other *** search
-
- #include "TraceLog.h"
- #include <PLStringFuncs.h>
- #include <Files.h>
- #include <Events.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdarg.h>
-
-
- short traceLogRefNum;
- FSSpec logSpec;
-
-
- void Trace_StartLog(FSSpec* spec, Boolean flushLog)
- {
- FInfo ignore;
-
- if (spec == NULL)
- {
- PLstrcpy (logSpec.name, "\pCASample Trace Log");
- logSpec.vRefNum = 0;
- logSpec.parID = 2;
- }
- else
- {
- logSpec = *spec;
- }
-
- if (FSpGetFInfo (&logSpec, &ignore))
- {
- FSpCreate (&logSpec, 'ttxt', 'TEXT', 0);
- }
-
- FSpOpenDF (&logSpec, fsRdWrPerm, &traceLogRefNum);
-
- if (flushLog)
- SetEOF (traceLogRefNum, 0);
-
- }
-
-
-
- void Trace_StopLog()
- {
- FSClose (traceLogRefNum);
- }
-
- void Trace_Log (char* str)
- {
- long count;
- char eol[2];
- char line[256];
- long eof;
-
-
- FSpOpenDF (&logSpec, fsRdWrPerm, &traceLogRefNum);
- GetEOF (traceLogRefNum, &eof);
- SetFPos (traceLogRefNum, fsFromStart, eof);
-
- count = strlen (str) + 1;
-
- FSWrite (traceLogRefNum, &count, str);
-
- count = 1;
- eol[0] = 0x0D;
- FSWrite (traceLogRefNum, &count, eol);
-
- FSClose(traceLogRefNum);
-
-
- }
-
- void _CASTrace(short traceLevel, char *fmt, ... )
- {
- va_list args;
-
- if (traceLevel >= TRACELEVEL)
- {
-
- char msg[512];
- strcpy(msg, "Log: ");
- va_start(args,fmt);
- vsprintf(msg+strlen(msg),fmt,args);
- va_end(args);
- strcat (msg, "");
-
- Trace_Log (msg);
-
- }
-
- }
-
-